<?php 
define('IN_WONDERSHARE', true);
session_start();
header("Content-type:text/html;charset=utf-8");
require('../includes/init.php');
require ('./configs/site_config.php');
require('./classes/control/control_release.php');
class release
 {
	var $release_c;
	/**
	 * @ 构造函数,实例化releaseControl
	 * @ __construct
	 */
 	
	public function __construct()
	{
		
		$this->release_c = new releaseControl();
	}
	
	/**
	* @函数index,返回默认列表
	* @param  NULL
	* @return  string
	*/
	function index()
	{
	  $url_info = $release_info = array();
		//分页处理
	  $web	= !empty($_POST['web']) ? trim($_POST['web']) : trim($_GET['web']);
	  $url	= !empty($_POST['url']) ? trim($_POST['url']) : trim($_GET['url']);
	  $type	= !empty($_POST['type']) ? trim($_POST['type']) : trim($_GET['type']);
	  $page = 1;
      if (!empty($_REQUEST['page'])) {
	  $page = (int)$_REQUEST['page'];
      }
	  if($web)
	  {
         $url_info = $this->release_c->get_url_info($page,2,$url,$web);
	  	 $release_info = $this->release_c->get_release_info('list_s',$url_info['page_info']['start'],20,$url,$web);
	  }
	  else
	  {
	  	$url_info = $this->release_c->get_url_info($page,1,$url);
	  	$release_info = $this->release_c->get_release_info('list',$url_info['page_info']['start'],20,$url);
	  }
      $GLOBALS['smarty']->assign('page_url',   $url_info['page_url']);
      $GLOBALS['smarty']->assign('release_info',$release_info );
      $GLOBALS['smarty']->assign('total',   $url_info['page_info']['total']);
	  $GLOBALS['smarty']->assign('url',$url );
	  $GLOBALS['smarty']->assign('web',$web );
	  $GLOBALS['smarty']->assign('type',$type );
	  $GLOBALS['smarty']->display('release_index.htm'); 
	  
	}
 	
	/**
	* @函数released_edit//增加，修改
	* @param  NULL
	* @return  string
	*/
	public function add_edit()
	{
 		$array = array
 		(
			'web' => trim($_POST['web']),
			'contents' => trim($_POST['contents']),
			'backup' => trim($_POST['backup']),
 			'web_type' => 105
 		);	
	 	if($_REQUEST['act'] == 'add')
	 	{
		   if($_POST['sub_from'])
		   {
			    $affect = $this->release_c->operate_release('add',0,$array);

		   }
		   
		   $site = array(
				'wondershare.com.br'	=> 105,
		   		'images.wondershare.com.br'	=> 105,
				'store.wondershare.com.br'	=> 105
				
		   );

		   $GLOBALS['smarty']->assign('AID',     $_SESSION['AID']);
		   $GLOBALS['smarty']->assign('MPower',     explode(',',$_SESSION['MPower']));
		   $GLOBALS['smarty']->assign('site',     $site);
		   $GLOBALS['smarty']->assign('title',     '网站');
		   $GLOBALS['smarty']->assign('form_act',     'add');
		   $GLOBALS['smarty']->display('release_info.htm');
		}
	}
	/**
	* @函数backup//备份数据库
	* @param  NULL
	* @return  string
	*/
	function backup()
	{
	    $this->release_c->release_backup();
	}
	
 	function rsync(){
 		
	    $affect = $this->release_c->rsync_c();
		if($affect == 1)
		{
			sleep(5);
			//发布cdn文件
			if (in_array(trim($_REQUEST['web']), $GLOBALS['cdn_www']) ) {
				$this->release_c->pub_cdn_file(trim($_REQUEST['web']));
			}
			echo  "<script> alert('发布成功！');window.location.href='/wondershare/release.php'</script>";
			exit;
		}else{
			echo  "<script>alert('{$affect}');window.location.href='/wondershare/release.php'</script>";
			exit;			 		
		}
	}
 }
$action    = $_REQUEST['action']; 
$release   = new release;
if(method_exists($release, $action)) 
{
	$release->$action();
}else{
	$release->index();
}
	
?>
